#include <iostream>
#include <list>
#include <map>

using namespace std;

// 声明加载六十甲子基础信息函数
std::map<int, std::string> initBaseInfo();

int main()
{
    // 设置字符编码
    system("chcp 65001");
    // 声明变量
    string ganzhi;
    int startYear;
    int endYear;

    cout << "请输入要查询的干支信息：" << endl;
    cin >> ganzhi;
    cout << "请输入要查询的时间范围的开始年份：" << endl;
    cin >> startYear;
    cout << "请输入要查询的时间范围的结束年份：" << endl;
    cin >> endYear;
    cout << "正在为您查询干支" << ganzhi << "，查询范围：公元" << startYear << "年 - 公元" << endYear << "年" << endl;
    std::map<int, string> stemsBranchesMap = initBaseInfo();
    // 声明一个容器存放
    list<int> yearList;
    int mapIndex = 58;
    for(int i = startYear; i <= endYear; i ++) {
        string temp = stemsBranchesMap[mapIndex];
        if(temp == ganzhi) {
            // cout << "公元" << i << "年符合" << endl;
            yearList.push_back(i);
        } else {
            // cout << "公元" << i << "年不符合" << endl;
        }
        if(mapIndex == 60) {
            mapIndex = 1;
        } else {
            mapIndex ++;
        }
    }
    cout << "符合干支" << ganzhi << "的西历年份有：" << endl;
    for (list<int>::iterator it = yearList.begin(); it != yearList.end(); ++it) {
        std::cout << "公元" << *it << "年" << endl;
    }
    return 0;
}
